<template>
  <div>
    <el-form
      :model="ruleForm"
      ref="ruleForm"
      label-width="130px"
      class="demo-ruleForm"
      size="mini"
      inline
    >
      <my-form-item label="客户编号">
        <el-input v-model="ruleForm.entNo" disabled></el-input>
      </my-form-item>

      <my-form-item label="客户名称" prop="entName">
        <el-input v-model="ruleForm.entName"></el-input>
      </my-form-item>

      <my-form-item label="曾用名">
        <el-input v-model="ruleForm.formerName"></el-input>
      </my-form-item>

      <my-form-item label="基本开户许可证">
        <el-input v-model="ruleForm.openAccountlicence"></el-input>
      </my-form-item>

      <my-form-item label="基本开户行">
        <el-input v-model="ruleForm.openAccountbank"></el-input>
      </my-form-item>

      <my-form-item label="项目来源" prop="projectSources">
        <el-select v-model="ruleForm.projectSources" placeholder="请选择项目来源" style="width: 100%;">
          <el-option label="项目经理营销" value="0"></el-option>
          <el-option label="存量客户" value="1"></el-option>
          <el-option label="银行推荐" value="2"></el-option>
          <el-option label="合作单位推荐" value="3"></el-option>
          <el-option label="其他" value="4"></el-option>
          <el-option label="相关部门及区局推荐" value="5"></el-option>
        </el-select>
      </my-form-item>

      <my-form-item label="区域(注册地)" prop="area">
        <el-cascader
          v-model="ruleForm.areaList"
          :options="areas"
          :props="{ checkStrictly: true,value:'label',label:'label' }"
          clearable
          filterable
        ></el-cascader>
      </my-form-item>

      <my-form-item label="所属行业" prop="industry">
        <el-select v-model="ruleForm.industry" placeholder="请选择活动区域" style="width: 100%;">
          <el-option label="采矿业" value="0"></el-option>
          <el-option label="制造业" value="1"></el-option>
        </el-select>
      </my-form-item>

      <my-form-item label="所属行业工信部" prop="industryPro">
        <el-select v-model="ruleForm.industryPro" placeholder="请选择活动区域" style="width: 100%;">
          <el-option label="农,林，木，渔业" value="0"></el-option>
          <el-option label="工业" value="1"></el-option>
          <el-option label="建筑业" value="2"></el-option>
        </el-select>
      </my-form-item>

      <my-form-item label="通讯地址">
        <el-input v-model="ruleForm.mailAddress"></el-input>
      </my-form-item>

      <my-form-item label="企业联系电话">
        <el-input v-model="ruleForm.entPhone"></el-input>
      </my-form-item>

      <my-form-item label="电子信箱">
        <el-input v-model="ruleForm.entEmail"></el-input>
      </my-form-item>

      <my-form-item v-for="item in list" :label="item.fieldName" :key="item.fieldCode">
        <el-input v-model="ruleForm[item.fieldCode]"></el-input>
      </my-form-item>
    </el-form>
  </div>
</template>

<script>
import { reject } from "q";
export default {
  // props:{
  //   type:{
  //     type:String,
  //     default:"add"
  //   }
  // },
  data() {
    return {
      // list: [
      //   {
      //     fieldCode: "col1",
      //     fieldName: "统一社会信用码",
      //     fieldType: "1"
      //   },
      //   {
      //     fieldCode: "col2",
      //     fieldName: "个人身份证号",
      //     fieldType: "2"
      //   },
      //   {
      //     fieldCode: "col3",
      //     fieldName: "年收入",
      //     fieldType: "3"
      //   }
      // ],
      list: [],
      ruleForm: {
        entNo: "",
        entName: "",
        formerName: "",
        openAccountlicence: "",
        openAccountbank: "",
        projectSources: "",
        areaList: [],
        area: "",
        industry: "",
        industryPro: "",
        mailAddress: "",
        entPhone: "",
        entEmail: ""
      },
      rules: {
        entName: [
          { required: true, message: "请输入客户名称", trigger: "blur" }
        ],
        projectSources: [
          { required: true, message: "请选择项目来源", trigger: "change" }
        ],
        area: [{ required: true, message: "请选择区域", trigger: "change" }],
        industry: [
          { required: true, message: "请选择所属行业", trigger: "change" }
        ],
        industryPro: [
          { required: true, message: "请选择所属行业工信部", trigger: "change" }
        ]
      },
      status: false,
      areas: [],
      tableName: "biz_ent_base"
    };
  },
  beforeMount() {
    //获取有效的增加字段
    this.getCols();

    this.list.forEach(item => {
      this.ruleForm[item.fieldCode] = "";
    });
  },
  mounted() {
    this.getAreaList();
  },
  methods: {
    //获取有效的增加字段
    getCols() {
      this.$api
        .formPost("/api/biz/reservedField/getCols", {
          tableName: this.tableName
        })
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.list = res.retBody;
          } else {
            this.$message({
              type: "error",
              message: res.retHead.message
            });
          }
        });
    },
    getData(entId) {
      this.$api
        .formPost("/api/biz/entBase/doGetById", {
          id: entId
        })
        .then(res => {
          console.log(res);
          if (res.retHead.code == "0000000") {
            this.ruleForm = res.retBody;
          } else {
            this.$message({
              type: "error",
              message: res.retHead.message
            });
          }
        });
    },
    doSave(id, path, name) {
      let that = this;
      return new Promise((resolve, reject) => {
        that.$api
          .post("/api/biz/entBase/doSubmit", {
            entBase: that.ruleForm,
            applicationPath: path,
            componentName: name,
            entId: id
          })
          .then(res => {
            if (res.retHead.code == "0000000") {
              // that.$message.success(res.retHead.message);
              resolve(res.retBody);
            } else {
              that.$message.error(res.retHead.message);
            }
          });
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {});
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    getAreaList() {
      this.$api.formPost("/api/auth/sysArea/doGetSysAreaVOList").then(res => {
        if (res.retHead.code == "0000000") {
          this.areas = res.retBody;
        }
      });
    }
  }
};
</script>
<style lang='scss' scoped>
</style>